package com.juzhencms.apps.busi.web;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.juzhencms.apps.base.common.database.DBTable;
import com.juzhencms.apps.base.common.util.WebUtil;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
@RequestMapping("/position")
public class PositionController extends BaseController{
	
	@RequestMapping(value="/provinceData",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String provinceData(HttpServletRequest request){
		List list=this.getCommonService().getJdbcDao().querySql("select province_id as id,province_name as text from "+DBTable.positionProvince+" order by position asc,id asc");
		
		return WebUtil.resultString(list,request);
		
	}
	
	@RequestMapping(value="/cityData",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String cityData(HttpServletRequest request){
		List list=new ArrayList();
		//System.out.println(request.getParameter("pid"));
		if(request.getParameter("pid")!=null && !request.getParameter("pid").equals("")) {
			list=this.getCommonService().getJdbcDao().querySql("select city_id as id,city_name as text from "+DBTable.positionCity+" where province_id=? order by position asc,id asc",new Object[] {request.getParameter("pid")});
		}
		
		return WebUtil.resultString(list,request);
	}
	
	@RequestMapping(value="/countyData",produces="text/html; charset=UTF-8")
	@ResponseBody
	public String countyData(HttpServletRequest request){
		List list=this.getCommonService().getJdbcDao().querySql("select county_id as id,county_name as text from "+DBTable.positionCounty+" where city_id=? order by position asc,id asc",new Object[] {request.getParameter("pid")});
		return WebUtil.resultString(list,request);
	}
	
	
}
